const { find } = require("./findFilesEx");
const rootPath = require("../../root");
const path = require("path");
const fs = require("fs");
const config = require("../../config.json");
function getFileNames(stylePath, isabs = true, ishasname = false) {
	let files = null;
	if (isabs) {
		files = find(path.join(rootPath, stylePath), false);
	} else {
		files = find(stylePath, false);
	}
	const newFiles = files.map((fileName) => {
		let name = undefined;
		if (!ishasname) {
			return path.parse(fileName).name;
		} else {
			return fileName;
		}
	});
	return newFiles;
}
function generatorStyleConfig(stylePath = config.modpath) {
	const newFiles = getFileNames(stylePath);
	const config = {
		modpath: stylePath,
		themepath: "temp/styles",
		sourcepath: "md",
		outpath: "dest",
		style: {},
	};
	newFiles.forEach((fileName) => {
		if (fileName === "pre") {
			config.style[fileName] = {
				stylepath: `${fileName}.css`,
				classname: fileName,
				theme: "atom-one-dark.css",
			};
		} else {
			config.style[fileName] = {
				stylepath: `${fileName}.css`,
				classname: fileName,
			};
		}
	});
	fs.writeFile(
		path.join(rootPath, "tempC.json"),
		JSON.stringify(config),
		(err) => {
			console.log(err);
		}
	);
}
module.exports = {
	getFileNames,
	generatorStyleConfig,
};
